home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / lasso.c < prev    next >
C/C++ Source or Header  |  2000-05-03  |  5KB  |  218 lines

  1. /* vidhrdw/lasso.c */
  2.  
  3. #include "driver.h"
  4. #include "vidhrdw/generic.h"
  5.  
  6. unsigned char *lasso_vram; /* 0x2000 bytes for a 256x256x1 bitmap */
  7. static int flipscreen,gfxbank;
  8. static struct tilemap *background;
  9.  
  10.  
  11.  
  12. /***************************************************************************
  13.  
  14.   Convert the color PROMs into a more useable format.
  15.  
  16. ***************************************************************************/
  17.  
  18. void lasso_vh_convert_color_prom(unsigned char *palette,unsigned short *colortable,const unsigned char *color_prom)
  19. {
  20.     int i;
  21.     for (i = 0;i < 0x40;i++)
  22.     {
  23.         int bit0,bit1,bit2;
  24.  
  25.  
  26.         /* red component */
  27.         bit0 = (*color_prom >> 0) & 0x01;
  28.         bit1 = (*color_prom >> 1) & 0x01;
  29.         bit2 = (*color_prom >> 2) & 0x01;
  30.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  31.         /* green component */
  32.         bit0 = (*color_prom >> 3) & 0x01;
  33.         bit1 = (*color_prom >> 4) & 0x01;
  34.         bit2 = (*color_prom >> 5) & 0x01;
  35.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  36.         /* blue component */
  37.         bit0 = (*color_prom >> 6) & 0x01;
  38.         bit1 = (*color_prom >> 7) & 0x01;
  39.         *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  40.  
  41.         color_prom++;
  42.     }
  43. }
  44.  
  45.  
  46.  
  47. /***************************************************************************
  48.  
  49.   Callbacks for the TileMap code
  50.  
  51. ***************************************************************************/
  52.  
  53. static void get_bg_tile_info(int tile_index)
  54. {
  55.     int tile_number = videoram[tile_index];
  56.     int attributes = videoram[tile_index+0x400];
  57.     SET_TILE_INFO(gfxbank,tile_number,attributes&0xf)
  58. }
  59.  
  60.  
  61.  
  62. /***************************************************************************
  63.  
  64.   Start the video hardware emulation.
  65.  
  66. ***************************************************************************/
  67.  
  68. int lasso_vh_start( void )
  69. {
  70.     background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  71.  
  72.     if (!background)
  73.         return 1;
  74.  
  75.     return 0;
  76. }
  77.  
  78.  
  79.  
  80. /***************************************************************************
  81.  
  82.   Memory handlers
  83.  
  84. ***************************************************************************/
  85.  
  86. WRITE_HANDLER( lasso_videoram_w )
  87. {
  88.     if( videoram[offset]!=data )
  89.     {
  90.         videoram[offset] = data;
  91.         tilemap_mark_tile_dirty( background, offset&0x3ff );
  92.     }
  93. }
  94.  
  95. WRITE_HANDLER( lasso_cocktail_w )
  96. {
  97.     flipscreen = data & 0x01;
  98.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  99.  
  100.     if (gfxbank != ((data & 0x04) >> 2))
  101.     {
  102.         gfxbank = (data & 0x04) >> 2;
  103.         tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
  104.     }
  105. }
  106.  
  107. WRITE_HANDLER( lasso_backcolor_w )
  108. {
  109.     int i,bit0,bit1,bit2,r,g,b;
  110.  
  111.  
  112.     /* red component */
  113.     bit0 = (data >> 0) & 0x01;
  114.     bit1 = (data >> 1) & 0x01;
  115.     bit2 = (data >> 2) & 0x01;
  116.     r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  117.     /* green component */
  118.     bit0 = (data >> 3) & 0x01;
  119.     bit1 = (data >> 4) & 0x01;
  120.     bit2 = (data >> 5) & 0x01;
  121.     g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  122.     /* blue component */
  123.     bit0 = (data >> 6) & 0x01;
  124.     bit1 = (data >> 7) & 0x01;
  125.     b = 0x4f * bit0 + 0xa8 * bit1;
  126.  
  127.     for( i=0; i<0x40; i+=4 ) /* stuff into color#0 of each palette */
  128.         palette_change_color( i,r,g,b );
  129. }
  130.  
  131.  
  132.  
  133. /***************************************************************************
  134.  
  135.   Display refresh
  136.  
  137. ***************************************************************************/
  138.  
  139. static void draw_sprites( struct osd_bitmap *bitmap )
  140. {
  141.     const struct GfxElement *gfx = Machine->gfx[2+gfxbank];
  142.     struct rectangle clip = Machine->drv->visible_area;
  143.     const unsigned char *finish = spriteram;
  144.     const unsigned char *source = spriteram + 0x80 - 4;
  145.     while( source>=finish )
  146.     {
  147.         int color = source[2];
  148.         int tile_number = source[1];
  149.         int sy = source[0];
  150.         int sx = source[3];
  151.         int flipy = (tile_number&0x80);
  152.         int flipx = (tile_number&0x40);
  153.         if( flipscreen )
  154.         {
  155.             sx = 240-sx;
  156.             flipx = !flipx;
  157.             flipy = !flipy;
  158.         }
  159.         else
  160.         {
  161.             sy = 240-sy;
  162.         }
  163.         drawgfx( bitmap,gfx,
  164.             tile_number&0x3f,
  165.             color,
  166.             flipx, flipy,
  167.             sx,sy,
  168.             &clip,TRANSPARENCY_PEN,0);
  169.  
  170.         source-=4;
  171.     }
  172. }
  173.  
  174. static void draw_lasso( struct osd_bitmap *bitmap )
  175. {
  176.     const unsigned char *source = lasso_vram;
  177.     int x,y;
  178.     int pen = Machine->pens[0x3f];
  179.     for( y=0; y<256; y++ )
  180.     {
  181.         for( x=0; x<256; x+=8 )
  182.         {
  183.             int data = *source++;
  184.             if( data )
  185.             {
  186.                 int bit;
  187.                 if( flipscreen )
  188.                 {
  189.                     for( bit=0; bit<8; bit++ )
  190.                     {
  191.                         if( (data<<bit)&0x80 )
  192.                             plot_pixel( bitmap, 255-(x+bit), 255-y, pen );
  193.                     }
  194.                 }
  195.                 else
  196.                 {
  197.                     for( bit=0; bit<8; bit++ )
  198.                     {
  199.                         if( (data<<bit)&0x80 )
  200.                             plot_pixel( bitmap, x+bit, y, pen );
  201.                     }
  202.                 }
  203.             }
  204.         }
  205.     }
  206. }
  207.  
  208. void lasso_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
  209. {
  210.     tilemap_update(ALL_TILEMAPS);
  211.     if (palette_recalc())
  212.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  213.     tilemap_render(ALL_TILEMAPS);
  214.     tilemap_draw(bitmap,background,0);
  215.     draw_lasso(bitmap);
  216.     draw_sprites(bitmap);
  217. }
  218.